package com.cssw.fyzb.web.controller;


import com.cssw.fyzb.base.web.context.UserContext;
import com.cssw.fyzb.base.web.domain.AjaxData;
import com.cssw.fyzb.base.web.domain.AjaxPage;
import com.cssw.fyzb.web.dto.FuncIdDto;
import com.cssw.fyzb.web.dto.CmfGiftDto;
import com.cssw.fyzb.web.dto.UpdateFuncDto;
import com.cssw.fyzb.web.service.CmfGiftService;
import com.cssw.fyzb.web.util.SplitUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@ApiModel("礼物相关接口")
@RestController
@RequestMapping("/gift")
public class CmfGiftController {

    @Autowired
    CmfGiftService cmfGiftService;

    @ApiOperation(value = "礼物列表", response = AjaxPage.class)
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "giftName", value = "菜单名称", paramType = "query", dataType = "string", required = false),
    })
    public AjaxPage list(int page, int limit, String giftName) {
        Map param = new HashMap();
        param.put("giftName", giftName);
        return cmfGiftService.list(page, limit, param);
    }

    @ApiOperation(value = "礼物详情", response = AjaxPage.class)
    @RequestMapping(value = "/info", method = RequestMethod.GET)
    public AjaxData info(Long giftId) {
        return cmfGiftService.info(giftId);
    }

    @ApiOperation(value = "新增礼物", response = AjaxData.class)
    @PostMapping(value = "/save")
    public AjaxData save(String type, Long cateId, String giftName, BigDecimal needCoin, BigDecimal giftYCoin, Integer sort, MultipartFile iconMiniFile, MultipartFile imageFile) throws Exception {
        return cmfGiftService.save(type, cateId, giftName, needCoin,giftYCoin,
                iconMiniFile, imageFile, sort, UserContext.getUserId());
    }

    @ApiOperation(value = "修改礼物", response = AjaxData.class)
    @PostMapping(value = "/update")
    public AjaxData update(Long giftId, String type, Long cateId, String giftName, BigDecimal needCoin, BigDecimal giftYCoin, Integer sort, MultipartFile iconMiniFile, MultipartFile imageFile) throws Exception {
        return cmfGiftService.update(giftId, type, cateId, giftName, needCoin,giftYCoin,
                iconMiniFile, imageFile, sort, UserContext.getUserId());
    }

    @ApiOperation(value = "删除礼物", response = AjaxData.class)
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public AjaxData delete(@RequestBody Map<String,Long> param) {
        return cmfGiftService.delete(param.get("giftId"),UserContext.getUserId());
    }


    @ApiOperation(value = "送出礼物记录", response = AjaxPage.class)
    @RequestMapping(value = "/listCmfLiveGift", method = RequestMethod.GET)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", paramType = "query", dataType = "string", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数", paramType = "query", dataType = "string", required = true),
    })
    public AjaxPage listCmfLiveGift(int page, int limit) {
        return cmfGiftService.listCmfLiveGift(page, limit);
    }

}
